<?php global $_webnukes;?>
<script type="text/javascript">
jQuery(document).ready(function($){
		$('#appointment_date').datetimepicker({ /**Code by coder 3.2.0 */
				dateFormat: 'yy-mm-dd',
				showSecond: true,
				timeFormat: 'HH:mm:ss'
		});
		$('#app_dob').datepicker({ /**Code by coder 3.2.0 */
				dateFormat: 'yy-mm-dd'
		});
});
</script>
<form action="" method="post" class="forms">
	<div class="section">
    	<?php 
		
		/** Submit request form to database */
		if(isset($_POST['requested_phy']))
		{
			global $wpnukes;
			if(is_a($wpnukes, 'wpnukes_doctors'))
			{
				$wpnukes->save_appointment($_POST);
			}else{
				$wpnukes = new wpnukes_doctors;
				$wpnukes->save_appointment($_POST);
			}
		}
		
		/** Generate fields */
		foreach($fields as $k=>$v): 
		
            $settings = $v;
			$field = $k;
			$user_settings = (isset($_POST) && count($_POST)) ? $_POST : array($k=>$v['std']);
			$html['element']  = '';
			$label_class = 'display_inline';
			$element_class = 'element';
			
			if(isset($v['heading']) && $v['heading']):?>
            	<div class="heading2"><h3><?php echo $v['heading']; ?></h3></div>
            <?php endif;?>
            
            <?php
			switch($settings['type'])
			{
				case "input":
					$html['element'] = form_input(array_merge(array('name'=>$field,'value'=>$user_settings[$field],'id'=>$field), (array) $settings['attrs']));
				break;
				
				case "dropdown":
					$settings['attrs'] = array_to_string(array_merge((array) $settings['attrs'], array('id'=>$field)));
					$html['element'] = form_dropdown($field, $settings['value'], $_webnukes->validation->set_value($field, $user_settings[$field]), $settings['attrs']);
				break;
				
				case "textarea":
					$label_class = 'textarea display_block';
					$element_class = '';
					$settingsvalue = empty($user_settings[$field]) ? $_webnukes->kvalue($settings, 'value') : $user_settings[$field];
					$settings['attrs'] = array_to_string(array_merge((array) $settings['attrs'], array('id'=>$field)));
					$html['element'] = form_textarea(array_merge(array('name'=>$field,'value'=>$_webnukes->validation->set_value($field, $settingsvalue),$settings['attrs']), (array) $settings['attrs']));
				break;
				
				case "multi_input":
					$html['element'] = '';
					foreach($settings['value'] as $key=>$val)
						$html['element'] .= '<span class="help-inline">'.slugtotext($key).': </span>'.form_input(array_merge(array('name'=>$field.'['.$key.']','value'=>$user_settings[$field][$key],'id'=>$key), (array) $settings['attrs']));
				break;
				
				case "checkbox":
				case "radio":
				$label_class = 'display_inline';
				foreach($settings['value'] as $key=>$val)
					$html['element'] .= '<label class="'.$settings['type'].' display_inline" for="'.$field.'">'.form_radio($field, $key, ($user_settings[$field] == $key) ? true : '',$settings['attrs']).' <span> '.$val.' </span></label>';
				break;
				case "timepicker": /**Code by coder 3.2.0 */
					$html['element'] = form_input(array_merge(array('name'=>$field,'value'=>$user_settings[$field],'id'=>$field), (array) $settings['attrs']));
				break;
				case "hidden":
					$html['element'] = form_input(array('type'=>'hidden','name'=>$field,'value'=>$user_settings[$field],'id'=>$field));
				break;
				
			}
			if($info = $_webnukes->kvalue($settings, 'info')) $html['element'] .= '<span>'.$info.'</span>';
			?>
            <div class="form_field">
                <label class="<?php echo $label_class; ?>"><?php echo $v['label']; ?> * :</label>
                <div class="<?php echo $element_class ?>">
            	<?php echo $html['element']; ?>
                </div>
                <div class="clear"></div>
            </div>
        <?php endforeach; ?>
        
        <input type="submit" value="<?php _e('Send Request', THEME_NAME); ?>" class="button">
    </div><!-- section ends -->
</form>